package demo;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;

public class ZipDemo {

	public static void main(String[] args) throws Exception {
		File file = new File("D:\\test");
		ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(
				String.valueOf(System.currentTimeMillis()) + ".zip"));
		for (File f : file.listFiles()) {
			ZipEntry entry = new ZipEntry(f.getName());
			InputStream input = new FileInputStream(f);
			zos.putNextEntry(entry);
			int len = 0;
			while ((len = input.read()) != -1) {
				zos.write(len);
			}
			input.close();
		}
		zos.flush();
		zos.close();
	}
}
